$(function () {
    // if ($("#socll").find(".font").outerHeight() > 650) {
    //     $("#socll").jscroll({
    //         W: "12px", //设置滚动条宽度
    //         BgUrl: "", //设置滚动条背景图片地址
    //         Bg: "#82817c", //设置滚动条背景图片position,颜色等
    //         Bar: {
    //             Pos: "up",//设置滚动条初始化位置在底部
    //             Bd: {Out: "#82817c", Hover: "#82817c"},//设置滚动滚轴边框颜色：鼠标离开(默认)，经过
    //             Bg: {Out: "#fff", Hover: "#fff"}
    //         },//设置滚动条滚轴背景：鼠标离开(默认)，经过，点击
    //         Btn: {
    //             btn: false, //是否显示上下按钮 false为不显示
    //             uBg: {Out: "ffffff", Hover: "#ffffff", Focus: "#ffffff", Bg: ""}, //设置上按钮背景：鼠标离开(默认)，经过，点击
    //             dBg: {Out: "ffffff", Hover: "#ffffff", Focus: "#ffffff", Bg: ""}
    //         }, //设置下按钮背景：鼠标离开(默认)，经过，点击
    //         Fn: function () {
    //         }//滚动时候触发的方法
    //     });
    // }
    nas.init();
    maps.init();
    baoming.init();
});


$.fn.mousewheel = function (Func) {
    return this.each(function () {
        var _self = this;
        _self.D = 0;//滚动方向
        if ($.browser.msie || $.browser.webkit) {
            _self.onmousewheel = function () {
                _self.D = event.wheelDelta;
                event.returnValue = false;
                Func && Func.call(_self);
            };
        } else {
            _self.addEventListener("DOMMouseScroll", function (e) {
                _self.D = e.detail > 0 ? -1 : 1;
                e.preventDefault();
                Func && Func.call(_self);
            }, false);
        }
    });
}

var nas = {
    list: 0,
    move: 0,
    init: function () {
        this.obj = $(".banner-box");
        if (!!$.browser.msie && parseInt($.browser.version) <= 6) {
            $(".banner-box .font1,.banner-box .font2").show();
        } else {
            $(".banner-box .font1,.banner-box .font2,.banner-box .pop1,.banner-box .pop2").css({
                opacity: 0
            }).show();
        }
        this.aniMate();
        this.baoming();
        this.bindFun();
    },
    aniMate: function () {
        var that = this;
        if (!!$.browser.msie && parseInt($.browser.version) <= 6) {
            this.obj.find(".font1").animate({
                top: 31
            }, 500);
            setTimeout(function () {
                that.obj.find(".font2").animate({
                    top: 138
                }, 500, function () {
                    that.obj.find(".pop1").animate({
                        left: 284
                    }, 500).show();
                    that.obj.find(".pop2").animate({
                        left: 470
                    }, 500).show();
                });
            }, 200);
        } else {
            this.obj.find(".font1").animate({
                top: 31,
                opacity: 1
            }, 500);
            setTimeout(function () {
                that.obj.find(".font2").animate({
                    top: 138,
                    opacity: 1
                }, 500, function () {
                    that.obj.find(".pop1").animate({
                        left: 284,
                        opacity: 1
                    }, 500);
                    that.obj.find(".pop2").animate({
                        left: 470,
                        opacity: 1
                    }, 500);
                });
            }, 200);
        }
    },
    baoming: function () {
        var that = this;
        if (that.move == 0) {
            that.obj.find(".bm").animate({
                top: 345
            }, 600, function () {
                that.move = 1;
                that.baoming();
            });
        } else {
            that.obj.find(".bm").animate({
                top: 365
            }, 600, function () {
                that.move = 0;
                that.baoming();
            });
        }
    },
    bindFun: function () {
        var that = this,
            length = $(".pic-scrll").find("ul").find("li").length;
        $(".pic-scrll").find(".left").click(function () {
            if (that.list == 0) {
                that.list = length - 1;
            } else {
                that.list--;
            }
            $(".pic-scrll").find("ul").find("li").fadeOut();
            $(".pic-scrll").find("ul").find("li").eq(that.list).fadeIn(200);
        });

        $(".pic-scrll").find(".right").click(function () {
            if (that.list == length - 1) {
                that.list = 0;
            } else {
                that.list++;
            }
            $(".pic-scrll").find("ul").find("li").fadeOut();
            $(".pic-scrll").find("ul").find("li").eq(that.list).fadeIn(200);
        });
    }
}

var baoming = {
    init: function () {
        this.obj = $(".banner-box");
        this.bindFun();
    },
    bindFun: function () {
        var that = this;
        that.obj.find(".bm").click(function () {
            $.Jui._showMasks(0.6);
            $(".rule-box").eq(0).css({
                left: $.Jui._position($(".rule-box"))[0],
                top: $.Jui._position($(".rule-box"))[1] < 0 ? 0 : $.Jui._position($(".rule-box"))[1]
            }).show();
            $(".rule-box").eq(0).find(".fonts").jscroll({
                W: "12px", //设置滚动条宽度
                BgUrl: "", //设置滚动条背景图片地址
                Bg: "#82817c", //设置滚动条背景图片position,颜色等
                Bar: {
                    Pos: "up",//设置滚动条初始化位置在底部
                    Bd: {Out: "#82817c", Hover: "#82817c"},//设置滚动滚轴边框颜色：鼠标离开(默认)，经过
                    Bg: {Out: "#fff", Hover: "#fff"}
                },//设置滚动条滚轴背景：鼠标离开(默认)，经过，点击
                Btn: {
                    btn: false, //是否显示上下按钮 false为不显示
                    uBg: {Out: "ffffff", Hover: "#ffffff", Focus: "#ffffff", Bg: ""}, //设置上按钮背景：鼠标离开(默认)，经过，点击
                    dBg: {Out: "ffffff", Hover: "#ffffff", Focus: "#ffffff", Bg: ""}
                }, //设置下按钮背景：鼠标离开(默认)，经过，点击
                Fn: function () {
                }//滚动时候触发的方法
            });
        });

        $(".rule-box").find(".close").click(function () {
            $.Jui._closeMasks();
            $(".rule-box").hide();
        });

        $(".rule-box").find(".c1").click(function () {
            $(".rule-box").hide();
            $(".rule-box").eq(1).css({
                left: $.Jui._position($(".rule-box").eq(1))[0],
                top: $.Jui._position($(".rule-box").eq(1))[1]
            }).show();
        });

        $(".rule-box").find(".c2").click(function () {
            $.Jui._closeMasks();
            $(".rule-box").hide();
        });

        $(".submits").click(function () {
            if (that.check()[0] == false) {
                $(this).tips(that.check()[1]);
                return false;
            }
        });
    },
    check: function () {
        var pass, str,
            phone = /^1[34578][0-9]{9}$/,
            mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

        function checkbox(obj) {
            for (var i = 0; i < obj.length; i++) {
                if (obj.eq(i).attr("checked") == "checked") {
                    return false;
                    break;
                }
            }
            return true;
        }

        if ($.trim($("input.name").val()) == "") {
            pass = false;
            str = "请填写姓名";
            return [pass, str];
        } else if ($.trim($("input.sex").val()) == "") {
            pass = false;
            str = "请填写性别";
            return [pass, str];
        } else if ($.trim($("input.age").val()) == "") {
            pass = false;
            str = "请填写年龄";
            return [pass, str];
        } else if ($.trim($("input.city-a").val()) == "") {
            pass = false;
            str = "请填写城市";
            return [pass, str];
        } else if (checkbox($(".type-box").eq(0).find("input"))) {
            pass = false;
            str = "请选择参赛形式";
            return [pass, str];
        } else if (checkbox($(".type-box").eq(1).find("input"))) {
            pass = false;
            str = "请选择伴奏形式";
            return [pass, str];
        } else if (!phone.test($("input.phone").val())) {
            pass = false;
            str = "请正确填写联系电话";
            return [pass, str];
        } else if ($.trim($("input.adress").val()) == "") {
            pass = false;
            str = "请填写联系地址";
            return [pass, str];
        } else if (!mail.test($("input.maile").val())) {
            pass = false;
            str = "请正确填写邮箱地址";
            return [pass, str];
        } else if ($.trim($("input.yueqi").val()) == "") {
            pass = false;
            str = "请填写参赛乐器";
            return [pass, str];
        } else if ($.trim($("input.verify").val()) == "") {
            pass = false;
            str = "请填写验证码";
            return [pass, str];
        }
        return true;
    }
}

var maps = {
    init: function () {
        if ($(".maps").length > 0) {
            this.bindFun();
        }
    },
    bindFun: function () {
        $(".maps").find(".list-y").mouseover(function () {
            var atr = $(this).attr("atr"),
                ctr = $(this).attr("ctr");
            $(".maps").find(".list-y").removeClass("on");
            $(this).addClass('on');
            $(".maps").find(".arear").find(".min").hide();
            $(".maps").find(".arear").find(".min").eq(atr).show();
            $(".maps").find(".arear").find("p").removeClass('on');
            $(".maps").find(".arear").find("p").eq(ctr).addClass('on');
            $(".maps").find(".citys").hide();
            $(".maps").find(".citys").eq(ctr).show();
        });

        $(".maps").find(".arear").find("p").mouseover(function () {
            var atr = $(this).attr("atr"),
                ctr = $(this).attr("ctr");
            $(".maps").find(".list-y").removeClass("on");
            $(".maps").find(".list-y").eq(ctr).addClass('on');
            $(".maps").find(".arear").find("p").removeClass('on');
            $(this).addClass('on');
            $(".maps").find(".citys").hide();
            $(".maps").find(".citys").eq(atr).show();
        });

        $(".maps").find("li").mouseover(function () {
            $(".maps").find("li").find(".min").hide();
            $(this).find(".min").show()
        });
    }
}


!(function ($) {
    $.Jui = $.Jui || {};
    $.extend($.Jui, {
        _showMasks: function (a) {
            var str = "<div class='body-mask' style='position:absolute; top:0; left:0; width:100%; height:" + $(document).height() + "px; background-color:#000;  z-index:98;'></div>";
            $("body").append(str);
            $(".body-mask").css("opacity", 0);
            $(".body-mask").animate({
                "opacity": a ? a : "0.8"
            });
        },
        _closeMasks: function () {
            var close = $(".body-mask");
            close.fadeOut(function () {
                close.remove();
            });
        },
        _getpageSize: function () {
            /*
             height:parseInt($(document).height()),
             width:parseInt($(document).width())
             */
            var de = document.documentElement, arrayPageSize,
                w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth,
                h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
            arrayPageSize = [w, h]
            return arrayPageSize;
        },
        _position: function (obj) {//计算对象放置在屏幕中间的值   obj:需要计算的对象
            var left = ((this._getpageSize()[0] - parseInt(obj.outerWidth())) / 2);
            var top = ((this._getpageSize()[1] - parseInt(obj.outerHeight())) / 2) + this._getpageScroll();
            return [left, top];
        },
        _getpageScroll: function () {
            var yScrolltop;
            if (self.pageYOffset) {
                yScrolltop = self.pageYOffset;
            } else if (document.documentElement && document.documentElement.scrollTop) {
                yScrolltop = document.documentElement.scrollTop;
            } else if (document.body) {
                yScrolltop = document.body.scrollTop;
            }
            return yScrolltop;
        },
        isie: !!$.browser.msie,
        isie6: (!!$.browser.msie && parseInt($.browser.version) <= 6),
        DOC: $(document),
        WIN: $(window),
        HEAD: $(document).find("head"),
        BODY: $(document).find("body")
    });

    function tips(a, arr) {
        return this.each(function () {
            var $this = $(this),
                str = '<div class="tips_layer" style="position: absolute; border-radius:5px; background-color:#ff6600; display:none; z-index:9995">\
                <div class="tips-text" style="padding:2px 5px; line-height:18px; color:#fff;">' + a + '</div>\
                <div class="diamond"></div>\
            </div>';
            if ($(".tips_layer")) {
                $(".tips_layer").remove();
            }
            $(str).appendTo("body");
            var $tips_text = $(".tips-text"),
                $tips_layer = $(".tips_layer");
            if (arr) {
                $tips_layer.css({
                    "top": arr.top,
                    "left": arr.left
                }).show();
            } else {
                $tips_layer.css({
                    "top": $this.offset().top - parseInt($this.height()) - 10,
                    "left": $this.offset().left + parseInt($this.width() / 2) - 30
                }).show();
            }
            setTimeout(function () {
                $tips_layer.remove();
            }, 2000);
        });
    }

    $.fn.tips = tips;

})(jQuery);


/*模拟滚动条(网络版)*/
;
(function ($) {
    $.fn.extend({
        jscroll: function (j) {
            return this.each(function () {
                var defaults = {
                    W: "12px",
                    BgUrl: "",
                    Bg: "#fff586",
                    Bar: {
                        Pos: "up",
                        Bd: {Out: "#f9f0d5", Hover: "#f9f0d5"},
                        Bg: {Out: "#fe970e", Hover: "#fe970e", Focus: "orange"}
                    },
                    Btn: {
                        btn: true, uBg: {Out: "#fe970e", Hover: "#fe970e", Focus: "orange", Bg: ""},
                        dBg: {Out: "#fe970e", Hover: "#fe970e", Focus: "orange", Bg: ""}
                    },
                    Fn: function () {
                    }
                }
                j = $.extend({}, defaults, j);
                var _self = this,
                    Stime, Sp = 0, Isup = 0,
                    dw = $(_self).width(), dh = $(_self).height() - 1,
                    sw = j.W ? parseInt(j.W) : 21,
                    sl = dw - sw,
                    bw = j.Btn.btn == true ? sw : 0;
                $(_self).css({overflow: "hidden", position: "relative", padding: "0px"});
                if ($(_self).children(".jscroll-c").height() == null) {//存在性检测
                    $(_self).wrapInner("<div class='jscroll-c' style='top:0px;z-index:19;zoom:1;position:relative'></div>");
                    $(_self).children(".jscroll-c").prepend("<div style='height:0px;overflow:hidden'></div>");
                    $(_self).append("<div class='jscroll-e' unselectable='on' style=' height:100%;top:0px;right:0;-moz-user-select:none;position:absolute;overflow:hidden;z-index:19; border-radius:5px;'>\n\
                                                 <div class='jscroll-u' style='position:absolute;top:0px;width:100%;left:0;background:blue;overflow:hidden'></div>\n\
                                                 <div class='jscroll-h' id='jscroll-h_ie' unselectable='on' style='background:green;position:absolute;left:0;-moz-user-select:none;border:1px solid;border-radius:5px;'></div>\n\
                                                 <div class='jscroll-d' style='position:absolute;bottom:0px;width:100%;left:0;background:blue;overflow:hidden'></div></div>"
                    );
                }
                var jscrollc = $(_self).children(".jscroll-c"),
                    jscrolle = $(_self).children(".jscroll-e"),
                    jscrollh = jscrolle.children(".jscroll-h"),
                    jscrollu = jscrolle.children(".jscroll-u"),
                    jscrolld = jscrolle.children(".jscroll-d");
                if ($.browser.msie) {
                    document.execCommand("BackgroundImageCache", false, true);
                }
                jscrollc.css({"padding-right": sw});
                jscrolle.css({width: sw, background: j.Bg, "background-image": "url(" + j.BgUrl + ")"});
                jscrollh.css({
                    top: bw,
                    background: j.Bar.Bg.Out,
                    "background-image": "url(" + j.BgUrl + ")",
                    "border-color": j.Bar.Bd.Out,
                    width: sw - 2
                });
                jscrollu.css({height: bw, background: j.Btn.uBg.Out, "background-image": "url(" + j.Btn.uBg.Bg + ")"});
                jscrolld.css({height: bw, background: j.Btn.dBg.Out, "background-image": "url(" + j.Btn.dBg.Bg + ")"});
                jscrollh.hover(function () {
                    if (Isup == 0) {
                        $(this).css({
                            background: j.Bar.Bg.Hover,
                            "background-image": j.BgUrl,
                            "border-color": j.Bar.Bd.Hover
                        })
                    }
                }, function () {
                    if (Isup == 0) {
                        $(this).css({
                            background: j.Bar.Bg.Out,
                            "background-image": j.BgUrl,
                            "border-color": j.Bar.Bd.Out
                        })
                    }
                })
                jscrollu.hover(function () {
                    if (Isup == 0) {
                        $(this).css({background: j.Btn.uBg.Hover, "background-image": j.BgUrl})
                    }
                }, function () {
                    if (Isup == 0) {
                        $(this).css({background: j.Btn.uBg.Out, "background-image": j.BgUrl})

                    }
                })
                jscrolld.hover(function () {
                    if (Isup == 0) {
                        $(this).css({background: j.Btn.dBg.Hover, "background-image": j.BgUrl})

                    }
                }, function () {
                    if (Isup == 0) {
                        $(this).css({background: j.Btn.dBg.Out, "background-image": j.BgUrl})

                    }
                })
                var sch = jscrollc.height();
                //var sh = Math.pow(dh,2) / sch ;//Math.pow(x,y)x的y次方
                var sh = (dh - 2 * bw) * dh / sch
                if (sh < 10) {
                    sh = 10
                }
                var wh = sh / 6//滚动时候跳动幅度
                //  sh = parseInt(sh);
                var curT = 0, allowS = false;
                jscrollh.height(sh);
                if (sch <= dh) {
                    jscrollc.css({padding: 0});
                    jscrolle.css({display: "none"})
                } else {
                    allowS = true;
                }
                if (j.Bar.Pos != "up") {
                    curT = dh - sh - bw;
                    setT();
                }
                jscrollh.bind("mousedown", function (e) {
                    j['Fn'] && j['Fn'].call(_self);
                    Isup = 1;
                    jscrollh.css({background: j.Bar.Bg.Focus, "background-image": j.BgUrl})
                    var pageY = e.pageY, t = parseInt($(this).css("top"));
                    $(document).mousemove(function (e2) {
                        curT = t + e2.pageY - pageY;//pageY浏览器可视区域鼠标位置，screenY屏幕可视区域鼠标位置
                        setT();
                    });
                    $(document).mouseup(function () {
                        Isup = 0;
                        jscrollh.css({
                            background: j.Bar.Bg.Out,
                            "background-image": j.BgUrl,
                            "border-color": j.Bar.Bd.Out
                        })
                        $(document).unbind();
                    });
                    return false;
                });
                jscrollu.bind("mousedown", function (e) {
                    j['Fn'] && j['Fn'].call(_self);
                    Isup = 1;
                    jscrollu.css({background: j.Btn.uBg.Focus, "background-image": j.BgUrl})
                    _self.timeSetT("u");
                    $(document).mouseup(function () {
                        Isup = 0;
                        jscrollu.css({background: j.Btn.uBg.Out, "background-image": j.BgUrl})
                        $(document).unbind();
                        clearTimeout(Stime);
                        Sp = 0;
                    });
                    return false;
                });
                jscrolld.bind("mousedown", function (e) {
                    j['Fn'] && j['Fn'].call(_self);
                    Isup = 1;
                    jscrolld.css({background: j.Btn.dBg.Focus, "background-image": j.BgUrl})
                    _self.timeSetT("d");
                    $(document).mouseup(function () {
                        Isup = 0;
                        jscrolld.css({background: j.Btn.dBg.Out, "background-image": j.BgUrl})
                        $(document).unbind();
                        clearTimeout(Stime);
                        Sp = 0;
                    });
                    return false;
                });
                _self.timeSetT = function (d) {
                    var self = this;
                    if (d == "u") {
                        curT -= wh;
                    } else {
                        curT += wh;
                    }
                    setT();
                    Sp += 2;
                    var t = 500 - Sp * 50;
                    if (t <= 0) {
                        t = 0
                    }
                    Stime = setTimeout(function () {
                        self.timeSetT(d);
                    }, t);
                }
                jscrolle.bind("mousedown", function (e) {
                    j['Fn'] && j['Fn'].call(_self);
                    curT = curT + e.pageY - jscrollh.offset().top - sh / 2;
                    asetT();
                    return false;
                });
                function asetT() {
                    if (curT < bw) {
                        curT = bw;
                    }
                    if (curT > dh - sh - bw) {
                        curT = dh - sh - bw;
                    }
                    jscrollh.stop().animate({top: curT});
                    var scT = -((curT - bw) * sch / (dh - 2 * bw));
                    jscrollc.stop().animate({top: scT});
                }

                function setT() {
                    if (curT < bw) {
                        curT = bw;
                    }
                    if (curT > dh - sh - bw) {
                        curT = dh - sh - bw;
                    }
                    jscrollh.css({top: curT});
                    var scT = -((curT - bw) * sch / (dh - 2 * bw));
                    jscrollc.css({top: scT});
                }

                $(_self).mousewheel(function (e) {
                    if (allowS != true)
                        return;
                    j['Fn'] && j['Fn'].call(_self);
                    if (this.D > 0) {
                        curT -= wh;
                    } else {
                        curT += wh;
                    }
                    setT();
                })
            });
        }
    });

})(jQuery);

